package com.ruoyi.fly.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fly.domain.Reimbursements;
import com.ruoyi.fly.domain.vo.ReferralrewardsVo;
import com.ruoyi.fly.domain.vo.ReimbursementsVo;
import com.ruoyi.fly.service.ReferralrewardsService;
import com.ruoyi.fly.service.ReimbursementsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;

import java.util.List;

/**
 * 分享消费奖励Controller
 */
@RestController
@RequestMapping("/finance")
@Api(tags = "财务管理")
public class ReferralrewardsController extends BaseController {
    @Autowired
    private ReferralrewardsService referralrewardsService;

    @Autowired
    private ReimbursementsService reimbursementsService;

    /**
     * 根据id获取分享消费奖励详细信息
     */
    @ApiOperation(value = "根据id获取分享消费奖励详细信息")
    @GetMapping(value = "/select/{id}")
    public R getInfo(@PathVariable("id") String id) {
        if (referralrewardsService.selectReferralrewardsById(id) == null){
            return R.fail("该分享消费奖励不存在");
        }
        return R.ok(referralrewardsService.selectReferralrewardsById(id));
    }

    /**
     * 修改分享消费奖励
     */
    @ApiOperation(value = "修改分享消费奖励")
    @PostMapping("/edit")
    public R edit(@RequestBody ReferralrewardsVo referralrewardsVo) {
        return referralrewardsService.updateReferralrewards(referralrewardsVo);
    }

    /**
     * 查询报销详情
     */
    @ApiOperation(value = "查询报销详情")
    @GetMapping("/reimbursements/select/{id}")
    public R selectReimbursementsById(@PathVariable("id") String id) {
        return R.ok(reimbursementsService.selectReimbursementsById(id));
    }

    /**
     * 查询报销列表
     */
    @ApiOperation(value = "查询报销列表")
    @PostMapping("/reimbursements/list")
    public TableDataInfo selectReimbursementsList(Reimbursements reimbursements) {
        startPage();
        List<Reimbursements> list = reimbursementsService.selectReimbursementsList(reimbursements);
        return getDataTable(list);
    }

    /**
     * 报销审核
     */
    @ApiOperation(value = "报销审核")
    @PostMapping("/reimbursements/edit")
    public R editReimbursements(@RequestBody ReimbursementsVo reimbursements) {
        return reimbursementsService.updateReimbursements(reimbursements);
    }

    /**
     * 删除报销
     */
    @ApiOperation(value = "删除报销")
    @PostMapping("/reimbursements/delete/{ids}")
    public R deleteReimbursementsById(@PathVariable("ids") String[] ids) {
        return reimbursementsService.deleteReimbursementsByIds(ids);
    }


}
